package com.unhz.taigu.interface_controllers.myProfile;

import com.qiniu.util.Json;
import com.unhz.generator.pojo.User;
import com.unhz.generator.pojo.UserDict;
import com.unhz.generator.utils.EmptyUtil;
import com.unhz.generator.utils.JsonResult;
import com.unhz.taigu.service.UserDictService;
import com.unhz.taigu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: 沈佳庆
 * @Description:
 * @Date: Created in 下午 2:52 2018/3/5 0005
 * @Modified By: V1.0.0
 */
@RestController
@RequestMapping("/IProfile")
public class IProfileController{

    @Autowired
    private UserService userService;

    @Autowired
    private UserDictService userDictService;

    /**
     * 查询个人资料
     * @param model
     * @param userId
     * @return
     */
    @RequestMapping("/selectProfile")
    public JsonResult selectProfile(Model model, @RequestParam(value= "userId",required = false) Integer userId){
        //用户信息
        User user = userService.selectById(userId);

        //用户信息数据字典
        List<UserDict> userDictList = userDictService.findAllType();
        if(EmptyUtil.isEmpty(user)){
            return JsonResult.failure("暂无此用户资料!");
        }
        model.addAttribute("user",user);
        model.addAttribute("userDictList",userDictList);
        return JsonResult.success("查询用户个人资料!",model);
    }

}
